package com.nepu.gmall.realtime.util;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

/**
 * @author chenshuaijun
 * @create 2023-02-27 21:59
 */
public class KeywordUtil {

    public static List<String> splitKeyword(String keyword) throws IOException {

        ArrayList<String> splitWords = new ArrayList<>();
        StringReader reader = new StringReader(keyword);
        IKSegmenter ikSegmenter = new IKSegmenter(reader, false);

        Lexeme next = ikSegmenter.next();

        while (next != null){
            String word = next.getLexemeText();
            splitWords.add(word);
            next = ikSegmenter.next();
        }

        return splitWords;
    }

    /*public static void main(String[] args) throws IOException {
        System.out.println(splitKeyword("Apple iPhoneXSMax (A2104) 256GB 深空灰色 移动联通电信4G手机 双卡双待"));
    }*/
}
